<template>
	<view>
		<view class="text-center margin-top-xl">
			<view class="cu-avatar round lg  ">
				<view class="cu-tag badge" :class="sex%2==0?'cuIcon-female bg-pink':'cuIcon-male bg-blue'"></view>
			</view>
			<p class=" text-orange margin-top-xs" @tap="outLogin">{{ isLogin ? '已登录':'去登录'}}</p>
			<p>用户名：{{userInfo.username}}</p>
			<p>创建时间：{{userInfo.createTime}}</p>
		</view>
		<view class="cu-list menu card-menu margin-top-xl margin-bottom-xl shadow-lg">
			<Buyed :comments="comments"></Buyed>
		</view>
		<test/>
	</view>
</template>

<script>
	import Buyed from '@/pages/buyed/Buyed.vue'
	export default {
		data() {
			return {
				myList:[
					{
						icon:'cuIcon-github',
						text:'我的订单'
					}
				],
				userId:0,
				//1为女，2为男
				sex:1,
				//登录状态控制
				isLogin:false,
				userInfo: {
					
				},
				comments: []
			}
		},
		components: {
			Buyed
		},
		mounted() {
			this.login()
		},
		methods: {
			getUserBuyed(userId) {
				this.$ajax.get('/film/session/getUserBuyed/' + userId, {
					t: '1684057983816',
					page: 1,
					limit: 10
				}).then(res => {
					this.comments = res.list
				})
			},
			outLogin(){
				uni.reLaunch({
					url:'/pages/login/login'
				})
				uni.removeStorage({
					key:'userInfo'
				})
			},
			getUserInfo(userId) {
				this.$ajax.get('/app/getUserInfo/' + userId, {
					t: '1684057983816',
					page: 1,
					limit: 10
				}).then(resInfo => {
					this.userInfo = resInfo.user
					this.isLogin = true
				})
			},
			async login(){
				let that = this
				uni.getStorage({
					key:'userInfo',
					success(res) {
						that.getUserInfo(res.data)
						that.getUserBuyed(res.data)
					}
				})
				
				
			}
		}
	}
</script>

<style scoped>
.cu-avatar{
	background-image: url('https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg');
}
</style>
